# Test

# Test:

OK () {
  local r=$?
  echo -n "$r "
  if [[ "$r" == "0" ]]; then
    echo "OK"
  else 
    echo "FAIL"
  fi
}

test_1 () { 
  test_abc_() { [[ "a" == "a" ]]; }
  test_abc_;
  OK
}

test_2 () { 
  test_abc_;
  OK
}

test_3 () {
  test_b_() { 
    test_b_a_ () { [[ "a" == "a" ]]; }
    test_b_a_
  }
  test_b_
  OK
}

test_4 () {
  set -e
  test_a_() { [[ "a" == "a" ]] && [[ "a" == "b" ]] || :; }
  test_a_
  OK
  [[ "a" == "a" ]] && [[ "a" == "b" ]] && echo "OK"
  [[ "a" == "a" ]] && [[ "a" == "b" ]] || echo "OK"
  set +e
}

test_5 () {
  echo -e "1abcdefghijklmnopqrstuvwxyz"
  echo -e "2abcdefghijklmnopqrstuvwxyz"
  echo -e "3abcdefghijklmnopqrstuvwxyz"
  echo -e "4abcdefghijklmnopqrstuvwxyz"
  echo -n "5abcdefghijklmnopqrstuvwxyz"
  tput cuu1
  echo -n "*"
  tput cuu1
  echo -n "##"
  tput cuu1
  echo -n "+++"
  echo 
  echo 
  echo 
  echo 
}

test_6 () {
  test_6_a_ () { hash "ls" 2>/dev/null || return 1; }
  test_6_b_ () { hash "abcdefg" 2>/dev/null || return 0; }
  test_6_c_ () { hash "abcdefg" 2>/dev/null; }
  test_6_d_ () { hash "abcdefg" 2>/dev/null || return 0; }
  test_6_a_
  OK
  test_6_b_
  OK
  test_6_c_
  OK
  test_6_d_
  OK
}

test_7 () {
  test_7_a_ () { 
    [[ "a" == "b" ]] || 
    {
      return 0
    } 
  }
  test_7_a_
  OK
}

test_8 () {
  #中文函数 () {
  #  echo "中文函数"
  #}
  #中文函数
}

for i in `seq 1 8`; do
  eval "test_$i"
done

#test_1
#test_2
#test_3
#test_4
#test_5
#test_6
#test_7
#test_8
